package com.example.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import static com.example.common.StatusCodes.*;

/**
 * Author: Zeran
 * Date: 2024-06-07 21:34
 * Desc:
 */
@NoArgsConstructor
@Data
@AllArgsConstructor
public class Result {
	@Schema(description = "状态码", example = "2001")
	private String code;
	@Schema(description = "状态信息", example = "成功")
	private String msg;
	@Schema(description = "返回数据", example = "{}")
	private Object data;

	public Result(String code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public static Result success() {
		return new Result(SUCCESS, SUCCESS_MSG);
	}

	public static Result success(String msg) {
		return new Result(SUCCESS, msg);
	}

	public static Result success(String code, String msg) {
		return new Result(code, msg);
	}

	public static Result data(Object data) {
		return new Result(SUCCESS, SUCCESS_MSG, data);
	}
	public static Result data(String msg,Object data) {
		return new Result(SUCCESS, msg, data);
	}

	public static Result sys_error() {
		return new Result(SYSTEM_ERROR, SYSTEM_ERROR_MSG);
	}

	public static Result sys_error(String msg) {
		return new Result(SYSTEM_ERROR, msg);
	}

	public static Result error(String code, String msg) {
		return new Result(code, msg);
	}
}
